<!--
* description: 战败审核
* author: mwh
* createdDate: 2020-11-21
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :dynamicSearchField="placeHolder"
      :dynamicButtons="tableButtons"
      :dynamicComponents="tableComponents"
      :dynamicApiConfig="apiConfig"
      :dynamicTableCols="tableCols"
      :dynamicFormFields="formField"
      :dynamicIsShowSelect="false"
      :dynamicIsInitTable="false"
      :dynamicIsColumnDrop="false"
      :callbackObj="callbackObj"
      :dynamicButtonsRight="tableButtonsRight"
      @changeToggleProp="changeToggleProp"
    />
    <edit
      :dynamicEditRowData="editRowData"
      :popupsVisible="editPopupsVisible"
      :key="editPopupsKey"
      :popupsState="editPopupsState"
      @close="close"
    ></edit>
  </div>
</template>
<script>
import { crmApis } from "@/api/apiList/crm.js";
import { requestGraphQL } from "@/api/commonRequest";
import { oneTableWithViewTemplateMixins } from "@/components/mixins/oneTableWithViewTemplateMixins";
import OneTableTemplate from "@/components/crm/Template/crmonePage";
import Vue from "vue";
import edit from "./DefeatClueReview_aud";

export default {
  name: "crmTodayPendingthread",
  // 组件混入对象
  mixins: [oneTableWithViewTemplateMixins],
  components: {
    OneTableTemplate,
    edit,
    dialogHeader: () => import("@/components/dialogHeader") //弹窗标题
  },
  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData(to.path, function() { 
      next();
    });
  },
  data() {
    let that=this
    return {
      editRowData:{},
      editPopupsKey:"editPopupsKey",
      editPopupsVisible:false,
      editPopupsState:[],
      callbackObj: {
        // 查询成功后回调
        onQueryReturn: response => {
          this.onQueryReturn(response);
        }
      },
      queryParam: "",
      placeHolder: `客户名称/电话`,
      // 网格查询API配置对象
      apiConfig: crmApis.clueServerQueryFromDlr,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "",
          size: "small",
          clickEvent: () => this.export(),
          // clickEvent: () => this.exportExcel("战败线索审核.xlsx", "战败线索审核", ),
          text: "导出"
        }
      ],
      tableButtonsRight: [
        {
          compKey: "btnKey10001",
          type: "",
          size: "small",
          icon: "el-icon-refresh",
          clickEvent: () => this.resetcur(),
          text: "重置"
        },
        {
          compKey: "btnKey10000",
          type: "primary",
          icon: "el-icon-search",
          size: "small",
          clickEvent: () => this.query(),
          text: "查询"
        }
      ],
      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableComponents
          : [
              {
                compKey: "compKey10",
                labelName: "线索单号",
                codeField: "serverOrder",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: false
              },
              {
                compKey: "compKey1",
                labelName: "客户名称",
                codeField: "custName",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: false
              },
              {
                compKey: "compKey2",
                labelName: "电话",
                codeField: "contactTel",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: false
              },
              {
                compKey: "compKey3",
                labelName: "申请时间",
                codeField: "applicantTimeStart,applicantTimeEnd",
                component: () =>
                  import("@/components/crm/Time/crmdtDatePicker"),
                type: "inputText",
                isMust: false
              },
              {
                compKey: "compKey15",
                labelName: "审核状态",
                codeField: "auditStatus",
                lookuptype: "UC0049",
                component: () => import("@/components/crm/lookupValue/lookupvalue"),
                type: "dropdownList",
                isMust: false
              },
              {
                compKey: "compKey4",
                labelName: "申请人",
                codeField: "applicant",
                component: () => import("@/components/org/commonInput"),
                type: "inputText",
                isMust: false
              },

              {
                compKey: "compKey5",
                labelName: "意向车系",
                codeField: "inteSeriesCode",
                component: () =>
                  import(
                    "@/components/crm/crmEjectWindows/crmIntenCarSeries/index"
                  ),
                type: "propus",
                isMust: false,
                isMul: false,
                // emitCode:this.inteSeriesChange
              },
              {
                compKey: "compKey6",
                labelName: "意向级别",
                codeField: "clueLevelCode",
                lookuptype: "LX141",
                attribute: "3",
                component: () =>
                  import("@/components/crm/lookupValue/lookupvalue"),
                type: "dropdownList",
                isMust: false,
                isMul: false
              },
              
              {
                compKey: "compKey11",
                labelName: "建单时间",
                codeField: "createdDateStart,createdDateEnd",
                component: () =>
                  import("@/components/crm/Time/crmdtDatePicker"),
                type: "inputText",
                isMust: false
              },
              {
                compKey: "compKey7",
                labelName: "线索渠道",
                codeField: "cantactWayCode",
                textField: "cantactWayName",
                lookuptype: crmApis.pcDbCantactWayQueryFindAll,
                component: () =>
                  import("@/components/crm/lookupValue/singleDropList"),
                type: "dropdownList",
                isMust: false,
                isMul: false,
                // changeCode: this.cantactWayChange
              },
              {
                compKey: "cantactWayCode",
                labelName: "一级信息来源",
                codeField: "infoChanMCode",
                textField: "infoChanMName",
                lookuptype: crmApis.pcDbInfoChanMQueryFind,
                changeCodeArray: [{ changCode: "cantactWayCode" }],
                component: () =>
                  import("@/components/crm/lookupValue/secondDropList"),

                type: "dropdownList",
                isMust: false,
                isMul: false
              },
              {
                compKey: "compKey12",
                labelName: "二级信息来源",
                codeField: "infoChanDName",
                component: () =>
                  import("@/components/crm/textbox/crmTextInput"),
                type: "",
                isMust: false
              },
              {
                compKey: "compKey14",
                labelName: "留资时间",
                codeField: "remainDataDateStart,remainDataDateEnd",
                component: () =>
                  import("@/components/crm/Time/crmdtDatePicker"),
                type: "date",
                isRequire: false,
                isMust: false
              },
              
            ],
      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
              {
                prop: "controlBtn",
                label: "操作",
                width: 100,
                align: "center",
                codeField: "controlBtn",
                isComponent: true,
                fixed: true,
                comps: [
                  {
                    compKey: "propKey1",
                    labelName: "审核",
                    codeField: "editControlBtn",
                    align: "center",
                    isShowLabel: true,
                    isShow: true,
                    clickEvent: index => this.edit(index),
                    disabled:"disabled1",
                    // clickEvent: this.edit,
                    // component: () => import("@/components/org/linkButton")
                    component: () => import("@/components/crm/crmLinkButton"),
                  },
                  {
                    compKey: "propKey2",
                    labelName: "详情",
                    codeField: "editControlBtn",
                    align: "center",
                    isShowLabel: true,
                    isShow: true,
                    clickEvent: index => this.detail(index),
                    // clickEvent: this.edit,
                    component: () => import("@/components/org/linkButton")
                  },
                ]
              },
              {
                prop: "serverOrder",
                label: "线索单号",
                width: 230,
                align: "center",
                fixed: true,
                isComponent: true,
                comps: [
                  {
                    compKey: "propKey1",
                    codeField: "serverOrder",
                    clickEvent: index => {
                      this.detail1(index);
                    },
                    component: () => import("@/components/crm/crmLinkButton"),
                    align: "center"
                  }
                ]
              },
              {
                prop: "custName",
                label: "客户名称",
                width: 150,
                align: "center",
                fixed: true,
                isComponent: true,
                comps: [
                  {
                    compKey: "propKey1",
                    codeField: "custName",
                    clickEvent: index => {
                      this.custDetail(index);
                    },
                    component: () => import("@/components/crm/crmLinkButton"),
                    align: "center"
                  }
                ]
              },
              {
                prop: "contactTel",
                label: "电话",
                width: 120,
                align: "center",
                fixed: true
              },
              {
                prop: "applicantTime",
                label: "申请时间",
                width: 150,
                align: "center",
                fixed: true
              },
              {
                prop: "auditStatusName",
                label: "审核状态",
                width: 120,
                align: "center"
              },
              {
                prop: "auditStatus",
                label: "审核状态",
                width: 120,
                align: "center",
                hidden:true
              },
              {
                prop: "applicant",
                label: "申请人",
                width: 120,
                align: "center"
              },
              {
                prop: "lostFailerDetail",
                label: "战败失控原因",
                width: 150,
                align: "center"
              },
              // {
              //   prop: "crruNodeName",
              //   label: "作业状态",
              //   width: 100,
              //   align: "center"
              // },
              {
                prop: "applicantId",
                label: "申请人ID",
                hidden: true,
                width: null,
                align: "center"
              },
              {
                prop: "crruNode",
                label: "作业类型编码",
                hidden: true,
                width: null,
                align: "center"
              },
              {
                prop: "carSeriesCn",
                label: "意向车系",
                width: 170,
                align: "center"
              },
              {
                prop: "clueLevelCode",
                label: "意向级别",
                width: 100,
                align: "center"
                // hidden:true
              },
              
              {
                prop: "createdDate",
                label: "建单时间",
                width: 150,
                align: "center"
              },
              {
                prop: "cantactWayName",
                label: "线索渠道",
                width: 160,
                align: "center"
              },
              {
                prop: "infoChanMName",
                label: "一级信息来源",
                width: 160,
                align: "center"
              },
              {
                prop: "infoChanDName",
                label: "二级信息来源",
                width: 160,
                align: "center"
                // hidden:true
              },
              {
                prop: "remainDataDate",
                label: "留资时间",
                width: 150,
                align: "center"
              },
              {
                prop: "failRecordCode",
                label: "审核编码",
                width: 150,
                align: "center",
                hidden:true,
              },
              {
                prop: "custId",
                label: "客户ID",
                width: null,
                align: "center",
                hidden: true
              },
              
            ],
      // 表单查询数据--重置查询条件
      formField: {
        // oemCode:"1",
        // groupCode: "1",
        applicant:"",
        inteSeriesCode: "",
        // applicantId: "",
        applicantTimeEnd: "",
        applicantTimeStart: "",
        createdDateStart:that.getStartDate() + " 00:00:00",
        createdDateEnd:that.getEndDate() + " 00:00:00",
        "createdDateStart,createdDateEnd": [
          that.getStartDate() + " 00:00:00",
          that.getEndDate() + " 00:00:00"
        ],
        cantactWayCode: "",
        infoChanDCode: "",
        infoChanDName:'',
        clueLevelCode: "",
        contactTel: "",
        custName: "",
        infoChanMCode: "",
        auditStatus:"",
        serverOrder: "",
        remainDataDateStart:"",
        remainDataDateEnd:"",
        statusArray: ["31"],
        clueLevelArray:["A","B","H","F","L"],
        handleCode: "1" //[0：本人线索查询，1：本店线索查询]
        // searchValue:"",//搜素字段
      },
      params: {
        applicantId: "",
        serverOrder: "",
        crruNode: ""
      },
      dialogVisible: false,
      form: {
        CNumber: {
          input: ""
        },
        Checkt: {
          input: ""
        },
        result: "1"
      },
      checked: true
    };
  },
  methods: {
    close(){

    },
    query() {
      let obj = {};
      obj.formField = JSON.parse(JSON.stringify(this.formField));
      this.$delete(obj.formField, "createdDateStart,createdDateEnd");
      this.queryTable(1, null, null, null, null, obj);
    },
    resetcur() {
      this.formField["createdDateStart,createdDateEnd"] = [
        this.getStartDate() + " 00:00:00",
        this.getEndDate() + " 00:00:00"
      ];
      this.reset();
      
    },
    getStartDate(){
      let dd = new Date();
      dd.setMonth(dd.getMonth()-1);
      let y = dd.getFullYear();
      let m = dd.getMonth()+1;
      let d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
      return y + "-" + (m < 10 ? "0" + m : m) + "-" + d;
    },
    getEndDate(){
      let dd = new Date();
      let y = dd.getFullYear();
      let m = dd.getMonth() + 1;
      let d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
      return y + "-" + (m < 10 ? "0" + m : m) + "-" + d;
    },
    changeToggleProp(){
      this.resetcur()
    },
    export(){
      let obj = {};
      obj.formField = JSON.parse(JSON.stringify(this.formField));
      this.$delete(obj.formField, "createdDateStart,createdDateEnd");
      this.exportExcel("战败失控线索审核.xlsx", "战败失控线索审核",-1,obj )
    },
    // inteSeriesChange(row){
    //   debugger
    //   this.formField.inteSeriesCode=row[0].carSeriesCode
    // },
    //详情
    detail(index){
      console.log(index);
      this.$crmcf.jumpDetailTag(this, "ClueDetail", "/ClueDetail", this.$refs.multipleTable.list[index]);
    },
    //处理
    // edit(index) {
    //   let that = this;
    //   that.params.applicantId = this.$refs.multipleTable.list[
    //     index
    //   ].applicantId;
    //   that.params.crruNode = this.$refs.multipleTable.list[index].crruNode;
    //   that.params.serverOrder = this.$refs.multipleTable.list[
    //     index
    //   ].serverOrder;
    //   that.dialogVisible = true;
    // },
    agree() {
      let that = this;
      that.checked = true;
      that.form.result = "1";
    },
    refuse() {
      let that = this;
      that.checked = false;
      that.form.result = "0";
    },
    //线索渠道change
    // cantactWayChange(){
    //  this.formField.infoChanMCode=''
    // },
    onQueryReturn(response) {
      let list = response.data[this.apiConfig.ServiceCode].rows;
      for (let i = 0; i < list.length; i++) {
        debugger
        if(list[i].auditStatus=="0"){
          list[i].disabled1="false"
        }else{
          list[i].disabled1="true"
        }
      }
    },
    detail1: function(index) {
      debugger;
      let that = this;
      //that.$router.push({ name: "ComplaintAssistHand", params: rowData });
      this.$crmcf.jumpDetailTag(
        that,
        "ClueDetail",
        "/ClueDetail",
        this.$refs.multipleTable.list[index]
      );
    },
    custDetail(index){
      let that = this;
      let queryObj = {
        type: "query",
        apiConfig: crmApis.custViewCustBaseInfoQueryFindAll,
        apiServices: [
          {
            apiQueryRow: [
              "custClassCode"
            ]
          }
        ],
        variables: {
          dataInfo: {
            dlrCustNo:that.$refs.multipleTable.list[index].custId
          }
        }
      };
      var paramD = that.$getParams(queryObj);
      requestGraphQL(paramD).then(response => {
        let results = response.data[queryObj.apiConfig.ServiceCode].rows[0];
        that.$refs.multipleTable.list[index].dlrCustNo=that.$refs.multipleTable.list[index].custId
        if (results.custClassCode == "0") {
          that.$crmcf.jumpDetailTag(that, "PerInfo", "/PerInfo", that.$refs.multipleTable.list[index]);
        }
        if (results.custClassCode == "1") {
          that.$crmcf.jumpDetailTag(that, "ComInfo", "/ComInfo", that.$refs.multipleTable.list[index]);
        }
      })
    },
  }
};
</script>
